﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using HAUtil;

using DotSpatial.Topology;

namespace HA.Data
{

    /// <summary>
    /// 用于存储点状featureobject,这里在考虑是组合关系还 是继承关系比较好
    /// </summary>
    [Serializable]
    public class PointFO : FeatureObject
    {
        public PointFO(string id, HCoordinate coords, Coverage coverage)
            : base(id,coverage)
        {

            this._coords = coords;



            this._refinePoint = new RefinePoints();


            //int nPeriods = this.Parent.ParentCM.Model.NPeriods;
            this._well = new BCWell();





        }


        HCoordinate _coords;

        public HCoordinate Coords
        {
            get { return _coords; }
            set { _coords = value; }
        }


        RefinePoints _refinePoint;

        public RefinePoints RefinePoint
        {
            get { return _refinePoint; }
            set { _refinePoint = value; }
        }


        BCWell _well;

        public BCWell Well
        {
            get { return _well; }
            set { _well = value; }
        }




        public override void ResetCoords(List<HCoordinate> coords)
        {
            this._coords = coords[0];

        }




        public override void MapToModFlow(List<double> stressPeriods, ModFlow.Domain.DomainLayer.ModFlowData mf, CoverageSetup setup)
        {
            base.MapToModFlow(stressPeriods,mf, setup);

            //只有点状的存在 refinedpoint 选项

            //if (this._refinePoint.Enabled)
            //{
            //    //执行具体的操作

            //}
            //else
            //{



            //}



        }



        #region 重写的方法

        public override object Clone()
        {
            PointFO pf = (PointFO)base.Clone();
            pf._coords = (HCoordinate)this._coords.Clone();
            pf._well = (BCWell)this._well.Clone();
            pf._refinePoint = (RefinePoints)this._refinePoint.Clone();

            return pf;
        }



        //internal override void OnNPeriodsChanged(int nPeriods)
        //{
        //    base.OnNPeriodsChanged(nPeriods);

        //    this._well.NPeriods = nPeriods;




        //}


        protected override void BuildIJKList(DotSpatial.Topology.Polygon[,] polys, List<int[,]> ibound, Polygon polyGridFrame, int From, int To)
        {

            this._lstIJK.Clear();



            ///当无需建立ijk时,点，线不需要考虑太多
            ///
            ///

            if (this._selectedSCType==MAPSCType.NONE)
            {
                return;
                
            }




           


            int nlayers = ibound.Count;


            Point p = new Point(this._coords.X ,this._coords.Y,this._coords.Z);

            int nrows = polys.GetLength(0);

            int ncols = polys.GetLength(1);


            for (int k = From - 1; k < To; k++)
            {

                ///当i在有效范围的时候,这里的i 对应的图层的索引

                if (k < nlayers && k > -1)
                {

                    for (int i = 0; i < nrows; i++)
                    {

                        for (int j = 0; j < ncols; j++)
                        {

                            if (ibound[k][i, j] != 0)
                            {


                                if (polys[i,j].Contains(p))
                                {

                                   
                              
                                    ValueResult vr = new ValueResult(i+1, j+1, k+1, 1);

                                    this._lstIJK.Add(vr);


                                    //继续寻找下一个层次 K

                                    continue;


                                    
                                }

                            


                              


                                
                            }



                            
                        }
                        
                    }


                    


                }

            }



           



           
        }




        protected internal override BCType GetCurrentBCType()
        {

            BCType bc = base.GetCurrentBCType();
            if (bc == null)
            {
                if (this._selectedSCType == MAPSCType.WELL)
                {
                    bc = this._well;

                }

            }

            else
            {

            }

            return bc;

        }


        /// <summary>
        /// 映射对应 的mt3dms算法
        /// </summary>
        /// <param name="data"></param>
        /// <param name="setup"></param>
        public override void MapToMT3dMS(List<double> stressPeriods, MT3DMS.DomainLayer.MT3DMSData data, CoverageSetup setup)
        {
            base.MapToMT3dMS(stressPeriods, data, setup);





        }

        #endregion


     



    }
}
